<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>

<!DOCTYPE html>
<html>
<head>
<title>项目管理工具</title>
<meta charset="gbk">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="bootstrap-3.3.7-dist/css/bootstrap.min.css">
<script src="bootstrap-3.3.7-dist/js/jquery.min.js"></script>
<script src="bootstrap-3.3.7-dist/js/bootstrap.min.js"></script>
<script type="text/javascript">
	$(function() {
		$(".dropdown-toggle").dropdown();
		
	});
	
	$(function() {
		$.post(
				"getProgressbarInfo.do",
				{projectId:${nowprojectid}},
				function(data){
					$("#jindutiao").empty();
					$("#jindutiao").append(
					'<div class="progress progress-striped active" style="width: 100%">'+
					'<div class="progress-bar progress-success"'+
						'style="width: '+data+'%" role="progressbar" aria-valuenow="30"'+
						'aria-valuemin="0" aria-valuemax="100">'+data+'%</div></div>'
				);},
				"json"
		);
	
		
	});
	
	
		
	
	
	function deleteProjectMember(urpid){
		
		var param = "projectid=${nowprojectid}&urpid="+urpid;
		$.ajax({
					type : 'post',
					url : 'deleteProjectMember.do',
					data : param,
					success : function(data) {
					
//					{"score":"12","urpid":1,"description":"项目经理","username":"李四"}]


						//	      	alert(data);
						var dataObj = eval("(" + data + ")");
						if(dataObj==null){
							alert('删除失败');
						}else{
						
							$('#tbody').empty();	
						for (var i = 0; i < dataObj.length; i++) {
							var proAttr = dataObj[i];
							var urpid = proAttr.urpid;
							var description = proAttr.description;
							var score = proAttr.score;
							var username = proAttr.username;
							
							var html;
							html="<tr><td><center>"+username+"</center></td><td><center>"+description+"</center></td><td><center>"+score+"</center></td><td><center><button type='button' class='btn btn-default btn-sm' onclick='deleteProjectMember("+urpid+")'>Remove";
							
							if(description=='项目经理'){
								html+="</button></center></td><td><center><div class='form-group'><button type='button' class='btn btn-default btn-sm' onclick='changeProjectMemberAuthority(this,"+urpid+")'>变更为项目成员</button>";
								
							
							}else{
								html+="</button></center></td><td><center><div class='form-group'><button type='button' class='btn btn-default btn-sm' onclick='changeProjectMemberAuthority(this,"+urpid+")'>变更为项目经理</button>";
								
								
							}
							html+="</div></center></td></tr>";
							$('#tbody').append(html);

						}
						
						
						}
						

					},
					error : function() {
						alert("出错了！");
					}
				});
		
		
		
		
		
		
		
		
		
		
		
		
	}
	
	function changeToPub(urpid,text,type){
		var param = "projectid=${nowprojectid}&urpid="+urpid+"&text="+text+"&type="+type;
		$.ajax({
			type : 'post',
			url : 'updateProjectMember.do',
			data : param,
			success : function(data) {
			
//			{"score":"12","urpid":1,"description":"项目经理","username":"李四"}]


				//	      	alert(data);
				var dataObj = eval("(" + data + ")");
				if(dataObj==null){
					alert('变更失败');
				}else{
				
					$('#tbody').empty();	
				for (var i = 0; i < dataObj.length; i++) {
					var proAttr = dataObj[i];
					var urpid = proAttr.urpid;
					var description = proAttr.description;
					var score = proAttr.score;
					var username = proAttr.username;
					
					var html;
					html="<tr><td><center>"+username+"</center></td><td><center>"+description+"</center></td><td><center>"+score+"</center></td><td><center><button type='button' class='btn btn-default btn-sm' onclick='deleteProjectMember("+urpid+")'>Remove";
					
					if(description=='项目经理'){
						html+="</button></center></td><td><center><div class='form-group'><button type='button' class='btn btn-default btn-sm' onclick='changeProjectMemberAuthority(this,"+urpid+")'>变更为项目成员</button>";
						
					
					}else{
						html+="</button></center></td><td><center><div class='form-group'><button type='button' class='btn btn-default btn-sm' onclick='changeProjectMemberAuthority(this,"+urpid+")'>变更为项目经理</button>";
						
						
					}
					html+="</div></center></td></tr>";
					$('#tbody').append(html);

				}
				
				
				}
				

			},
			error : function() {
				alert("出错了！");
			}
		});
	}
	
	
	function changeToManager(urpid,text,type){
		
		var param = "projectid=${nowprojectid}&urpid="+urpid+"&text="+text+"&type="+type;
		$.ajax({
			type : 'post',
			url : 'updateProjectMember.do',
			data : param,
			success : function(data) {
			
//			{"score":"12","urpid":1,"description":"项目经理","username":"李四"}]


				//	      	alert(data);
				var dataObj = eval("(" + data + ")");
				if(dataObj==null){
					alert('变更失败');
				}else{
				
					$('#tbody').empty();	
				for (var i = 0; i < dataObj.length; i++) {
					var proAttr = dataObj[i];
					var urpid = proAttr.urpid;
					var description = proAttr.description;
					var score = proAttr.score;
					var username = proAttr.username;
					
					var html;
					html="<tr><td><center>"+username+"</center></td><td><center>"+description+"</center></td><td><center>"+score+"</center></td><td><center><button type='button' class='btn btn-default btn-sm' onclick='deleteProjectMember("+urpid+")'>Remove";
					
					if(description=='项目经理'){
						html+="</button></center></td><td><center><div class='form-group'><button type='button' class='btn btn-default btn-sm' onclick='changeProjectMemberAuthority(this,"+urpid+")'>变更为项目成员</button>";
						
					
					}else{
						html+="</button></center></td><td><center><div class='form-group'><button type='button' class='btn btn-default btn-sm' onclick='changeProjectMemberAuthority(this,"+urpid+")'>变更为项目经理</button>";
						
						
					}
					html+="</div></center></td></tr>";
					$('#tbody').append(html);

				}
				
				
				}
				

			},
			error : function() {
				alert("出错了！");
			}
		});
	}
	
	
	function changeProjectMemberAuthority1(text,urpid){
		
		if(text=="变更为项目经理"){
			var a=0;
			for (var i = 0; i <$('#tbody tr').size(); i++) {
				var description= $('#tbody tr').eq(i).find('td:nth-child(2)').text();
				if(description=="项目经理"){
					if(confirm("已有项目经理，是否更换项目经理？")){
						
						changeToManager(urpid,text,0);
						a=1;
					}else{
						a=1;
					}
				
						
				}
				
				
			}
			
		
			if(a==0){
				changeToManager(urpid,text,1);
			}
			
		}else{
			//变为项目成员
			
			changeToPub(urpid,text,3);
			
		}
		
	}
	
	function changeProjectMemberAuthority(obj,urpid){
		var text= $(obj).text();
		
		changeProjectMemberAuthority1(text,urpid);
		
	}
	function addProjectMember(nowprojectid){
		var userid= $('#projectMember').val();
		var roleid=$('#addRole').val();
		if(userid==0||roleid==0){
			alert("请选择成员和角色！");
		}else{
			
			
			
			
			
			
			
			
			
			
		var param = "projectid=${nowprojectid}&roleid="+roleid+"&userid="+userid;
		$.ajax({
					type : 'post',
					url : 'addProjectMember.do',
					data : param,
					success : function(data) {
					
//					{"score":"12","urpid":1,"description":"项目经理","username":"李四"}]


						//	      	alert(data);
						var dataObj = eval("(" + data + ")");
						if(dataObj==null){
							alert('添加失败');
						}else{
						
							$('#tbody').empty();	
						for (var i = 0; i < dataObj.length; i++) {
							var proAttr = dataObj[i];
							var urpid = proAttr.urpid;
							var description = proAttr.description;
							var score = proAttr.score;
							var username = proAttr.username;
							var html;
							html="<tr><td><center>"+username+"</center></td><td><center>"+description+"</center></td><td><center>"+score+"</center></td><td><center><button type='button' class='btn btn-default btn-sm' onclick='deleteProjectMember("+urpid+")'>Remove";
							
							if(description=='项目经理'){
								html+="</button></center></td><td><center><div class='form-group'><button type='button' class='btn btn-default btn-sm' onclick='changeProjectMemberAuthority(this,"+urpid+")'>变更为项目成员</button>";
								
							
							}else{
								html+="</button></center></td><td><center><div class='form-group'><button type='button' class='btn btn-default btn-sm' onclick='changeProjectMemberAuthority(this,"+urpid+")'>变更为项目经理</button>";
								
								
							}
							html+="</div></center></td></tr>";
							$('#tbody').append(html);

						}
						
						
						}
						

					},
					error : function() {
						alert("出错了！");
					}
				});
		
		}
	}
	
	
	$(function() {
		var projectMember = document.getElementById("projectMember");
		var param = "teamid=${nowteamid}";
		$.ajax({
					type : 'post',
					url : 'getAllTeamMeber.do',
					data : param,
					success : function(data) {
						


						//	      	alert(data);
						var dataObj = eval("(" + data + ")");

						for (var i = 0; i < dataObj.length; i++) {

							var proAttr = dataObj[i];
							var userid = proAttr.userId;
							var username = proAttr.userName;
							var newOption = new Option(username, userid);
							
							projectMember.options.add(newOption);
						

						}

					},
					error : function() {
						alert("出错了！");
					}
				});
		
	});
	
	
	var password_IsTrue=false;
	function checkPass(){
	
		var password = document.getElementById("password").value;
		var msg = document.getElementById("msg");
		var param="password="+password;
		$.ajax({
			type : 'post',
			url : 'checkPassword.do',
			data : param,
			success : function(data) {
	//		alert(encodeURIComponent(data));
			var value= $.trim(data);
	//		alert(encodeURIComponent(value));
			  if(value=="ok"){
				  password_IsTrue=true;
			         msg.innerHTML="密码正确";
			  }
			  if(value=="no"){
			        	 password_IsTrue=false;
			         msg.innerHTML="密码错误";
			   }
			
					      	
			

			},
			error : function() {
				alert("出错了！");
			}
		});
		
	}	
	
	function deleteProject(){
		if(password_IsTrue){
			
			 top.location.href="deleteProject.do?projectid=${project.projectId}&teamid=${nowteamid}";
		
		}else{
			alert("密码不能为空或密码错误");
		}
	}
	
	
	$(function() {
		$('#deleteProject')
				.on(
						'hidden.bs.modal',
						function() {
							$('#msg').empty();
						})
	});
	
</script>

<style type="text/css">
body {
	margin: 0px;
	background: url(style/image/background/bangongshi1xh.jpg) no-repeat;
	background-size: 100% 100%;
	background-attachment: fixed;

}
.group {
	height: 400px;
	width: 800px;
}

.grouplist {
	float: left;
	height: 200px;
	width: 400px;
	font-size: 15px;
}

.grouplist:hover {
	background-color: #EEEED1;
}

.im {
	padding-top: 25px;
	float: left;
	height: 150px;
	width: 100px;
}

.imright {
	float: left;
	padding-top: 25px;
	padding-left: 20px;
	height: 200px;
	width: 300px;
	line-height: 2.0;
}

.typetop {
	
}

.typechild {
	margin-left: 750px;
}
</style>
</head>
<body>

	<div class="container">
		<div class="row clearfix">
			<div class="col-md-12 column">
				<nav class="navbar navbar-default" role="navigation">
					<div class="navbar-header">
						<button type="button" class="navbar-toggle" data-toggle="collapse"
							data-target="#bs-example-navbar-collapse-1">
							<span class="sr-only">Toggle navigation</span><span
								class="icon-bar"></span><span class="icon-bar"></span><span
								class="icon-bar"></span>
						</button>

					</div>

					<div class="collapse navbar-collapse"
						id="bs-example-navbar-collapse-1">
						<ul class="nav navbar-nav">

							<li class="dropdown"><a href="#" class="dropdown-toggle"
								data-toggle="dropdown">项目管理工具<strong class="caret"></strong></a>
								<ul class="dropdown-menu">

									<li class="divider"></li>
									<li><a>切换团队</a></li>
									<li class="divider">切换团队</li>
									<c:if test="${empty allTeam}">
									</c:if>
									<c:if test="${not empty allTeam}">
										<c:forEach var="team" items="${allTeam}">
											<c:if test="${team.teamid eq nowteamid}">
												<li><a href="gotoTeamDetail.do?teamid=${team.teamid}">${team.teamname}
														&nbsp; &nbsp;<span class="glyphicon glyphicon-ok"></span>
												</a></li>
											</c:if>
											<c:if test="${team.teamid  ne nowteamid}">
												<li><a href="gotoTeamDetail.do?teamid=${team.teamid}">${team.teamname}</a></li>
											</c:if>

										</c:forEach>
										<li class="divider">团队管理</li>
										<li><a href="gotoTeamList.do">团队管理</a></li>
									</c:if>

								</ul></li>
						</ul>

						<ul class="nav navbar-nav navbar-right">
							<li><a><img	 src="${currentUser.headimage}" width="27" height="27">
							</a></li>
							<li><a>HI!，${currentUser.userName}</a></li>
							<li class="dropdown"><a href="#" class="dropdown-toggle"
								data-toggle="dropdown"><span
									class="glyphicon glyphicon-bell"></span>${applyPartListSize}<strong
									class="caret"></strong></a>
								<ul class="dropdown-menu">
									<c:if test="${empty applyPartList}">

										<li><a href="gotoTeamDetail.do?teamid=${nowteamid}">暂时没有通知</a></li>
									</c:if>
									<c:if test="${not empty applyPartList}">
										<c:forEach var="applyUser" items="${applyPartList}">


											<li><a href="gotoTeamDetail.do?teamid=${nowteamid}">${applyUser.username}&nbsp;申请加入团队</a></li>

										</c:forEach>
										<li class="divider"></li>
										<li><a href="gotoTeamDetail.do?teamid=${nowteamid}">更多</a></li>
									</c:if>

								</ul></li>
							<li><a href="logout.do">注销</a></li>
						</ul>
					</div>

				</nav>
			</div>
		</div>



		<div class="row clearfix">
			<div class="col-md-3 column">
				<ul class="nav nav-stacked nav-tabs">
					<li ><a
						href="gotoTeamDetail.do?teamid=${nowteamid}">团队</a></li>
					</br>
					<li class="active"><a href="gotoProjectList.do?teamid=${nowteamid}">项目</a></li>
					</br>
						<li><a href="gotoUserinfo.do?teamid=${nowteamid}">信息</a></li>

				</ul>
			</div>


			<div class="col-md-9 column">
				<h4>${project.projectName}</h4>
				<div class="tabbable" id="tabs-458508">
					<ul class="nav nav-tabs">
						<li class="active"><a href="#panel-876035" data-toggle="tab">项目进度</a>
						</li>
						<li><a href="#panel-808913" data-toggle="tab">项目成员</a></li>
						<li><a href="#panel-808914" data-toggle="tab">项目设置</a></li>


					</ul>
					<div class="tab-content">
						<div class="tab-pane active" id="panel-876035">
							</br>
							</br>
							
							<label>项目进度:</label>
						<div id="jindutiao"></div>
						</div>
						<div class="tab-pane" id="panel-808913">



							<div class="typetop">
								<div class="typechild"></div>
							</div>






							<!-- type2 start -->
							<div id="type2">
								<div class="table-responsive">
									<table class="table">

										<thead>
											<tr>
												<th><center>成员名称</center></th>
												<th><center>成员身份</center></th>
												<th><center>项目评分</center></th>
												<th><center>移除</center></th>
												<th><center>变更角色</center></th>
											</tr>
										</thead>
										<tbody id="tbody">


											<c:if test="${empty projectMember}">

											</c:if>
											<c:if test="${not empty projectMember}">
												<c:forEach var="pmember" items="${projectMember}">
													<tr>
														<td><center>${pmember.username}</center></td>
														<td><center>${pmember.description}</center></td>
														<td><center>${pmember.score}</center></td>
														<td><center>
																<button type="button" class="btn btn-default btn-sm"
																	onclick="deleteProjectMember(${pmember.urpid})">
																	Remove</button>
															</center></td>
														<td ><center>
																<div class="form-group">
																	<c:if test="${pmember.description eq '项目经理'}">
																		<button type="button" class="btn btn-default btn-sm"
																		onclick="changeProjectMemberAuthority(this,${pmember.urpid})">变更为项目成员</button>
																
																	</c:if>
																	<c:if test="${pmember.description ne '项目经理'}">
																		<button type="button" class="btn btn-default btn-sm"
																		onclick="changeProjectMemberAuthority(this,${pmember.urpid})">变更为项目经理</button>
																
																	</c:if>
																	</div>
															</center></td>
													</tr>
												</c:forEach>
											</c:if>





										</tbody>
									</table>
								</div>

								<!--  
								<div class="form-group">
									<label for="name">新增成员</label> <select id="projectMember"
										class="form-control">
										<option value="0">--请选择--</option>
									</select>
								</div>
								<div class="form-group">
								<label for="name">成员身份</label> 
									<select class="form-control">
										<option value="0">--请选择--</option>
										<option value="2">项目经理</option>
										<option value="3">项目成员</option>
									</select>
									</center>
								</div>
								<button type="button" class="btn btn-default btn-lg btn-block"
								onclick="addGroupMember()">增加成员</button>

-->


								<div>
									<center>
										<label for="name">新增成员</label> <select id="projectMember">
											<option value="0">--请选择--</option>
										</select> <label for="name">成员身份</label> <select id="addRole">
											<option value="0">--请选择--</option>
											<option value="2">项目经理</option>
											<option value="3">项目成员</option>
										</select>


										<button type="button" class="btn btn-default btn-sm"
											onclick="addProjectMember(${nowprojectid})">增加成员</button>
									</center>
								</div>








							</div>
							<!-- type2 end -->














						</div>
						<div class="tab-pane" id="panel-808914">


							<form class="form" id="form-info" action="updateProjectInfo.do" method="post">
								<div class="form-group">
									<label for="name">项目名称</label> <input name="projectName"
										id="projectName" type="text" class="form-control" 
										style="width: 500px;" value="${project.projectName}">
								</div>
								<div class="form-group">
									<label for="name">项目描述</label>
									<textarea name="description" id="description"
										style="width: 500px;" value="${project.projectDescription}"
										class="form-control" rows="3">${project.projectDescription}</textarea>
								</div>
								<input type="hidden" name="projectid" value="${project.projectId }">
								<input type="hidden" name="teamid" value="${nowteamid}">
								<div class="form-group">
									<button type="submit" id="btn-save-setting"
										class="btn btn-primary btn-large">保存设置</button>
								</div>
							</form>


							</br>
							<div>
								&nbsp; <a data-toggle="modal" data-target="#deleteProject">删除项目</a><br><br>
							</div>





							<!-- 模态框（Modal） -->
					   <div class="modal fade" id="deleteProject" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
						<div class="modal-dialog">
							<div class="modal-content">
								<div class="modal-header">
									<button type="button" class="close" data-dismiss="modal" aria-hidden="true">
										&times;
									</button>
									<h4 class="modal-title" id="myModalLabel">
										删除项目
									</h4>
								</div>
								
								<div class="modal-body">
								<form action="" method="post"> 
								    <input type="password" name="password" id="password" placeholder="登录密码" style="width: 400px;" onblur="checkPass()"><span id="msg"></span><br><br>
									
									<input type="button"  onclick="deleteProject()" value="提交"/>
								</form>
								</div>
								<div class="modal-footer">
									<button type="button" class="btn btn-default" data-dismiss="modal">取消
									</button>
									
								</div>
							</div><!-- /.modal-content -->
						</div><!-- /.modal -->
						</div>








						</div>

					</div>

				</div>
			</div>




		</div>
</body>
</html>

